class UsersController < ApplicationController
  before_filter :find_user, :except => [:index, :new, :create]

  
  def index
    @users = User.find(:all, :order => "name")
  end

  def show
  end
  

  
  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])

    if @user.save 
      @current_user  = @user
      session[:user] = @user.id 

      flash[:notice] = "Successfully Signed up"
      redirect_to :action => "show", :id => @user.id
    else
      render :action => "new"
    end
  end
  

  
  def edit
  end

  def update
    if @user.update_attributes(params[:user])
      flash[:notice] = 'User successfully updated.'
      redirect_to :action => "show", :id => @user.id
    else
      render :action => "edit"
    end
  end

  def destroy
    @user.destroy
    flash[:notice] = 'User successfully destroyed.'
    redirect_to :action => "index"
  end
  
  
  private

  def find_user
    @user = User.find(params[:id])
  end
end